﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Jxym.DBUtility;
using Jxym.wlkc2011.Module.Default.model;
using System.Data.SqlClient;

namespace Jxym.wlkc2011.Module.Default.server.notice
{
    public partial class noticeDel : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
                int modelid = 0;
                if (Request.Params["modelid"] != null) modelid = Convert.ToInt32(Request.Params["modelid"]);
                //验证用户权限
                if (MyGet.GetPermissionsValidation(modelid,"D", Jxym.Common.Request.AdminID("user")))
                {
                    string returnVaoue = "", listIds = ""; ;

                    ArrayList list = new ArrayList();

                    if (Request.Params["ID"] != null)
                    {
                        string idstr = Request.Params["ID"];

                        string[] ids = idstr.Split(',');

                        MsSqlDal<model.Notice> iUi = new MsSqlDal<model.Notice>();

                        foreach (string id in ids)
                        {
                            //判断该通知发布人是不是当前用户
                            Notice notice = iUi.GetModel("ID = " + id, null);
                            if (notice.AddUser.Equals(Jxym.Common.Request.AdminID("user")))
                            {
                                try
                                {
                                    int count = 0;

                                    count = iUi.Delete(id);

                                    if (count > 0) { list.Add(id); }
                                }
                                catch (Exception)
                                {

                                }
                            }
                        }
                        if (list.Count > 0)
                        {
                            foreach (string id in list)
                            {
                                listIds += id + ",";
                            }

                            listIds = listIds.TrimEnd(',');

                            Response.Write("{'success':true,'count':" + list.Count + ",'ids':'" + listIds + "','msg':'" + returnVaoue + "'}");
                        }
                        else 
                        {
                            Response.Write("{'success':false,'msg':'对不起，您没有删除权限'}");
                        }
                    }
                }
                else
                {
                    Response.Write("{'success':false,'msg':'对不起，您没有删除权限'}");
                }
            }
        }
    }
}